package cn.stylefeng.guns.modular.goods.type.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.goods.type.entity.Type;
import cn.stylefeng.guns.modular.goods.type.model.params.TypeParam;
import cn.stylefeng.guns.modular.goods.type.model.result.TypeResult;
import cn.stylefeng.guns.modular.goods.type.service.TypeService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 控制器
 *
 * @author SYT
 * @Date 2020-10-13 11:24:10
 */
@Controller
@RequestMapping("/type")
public class TypeController extends BaseController {

    private String PREFIX = "/type";

    @Autowired
    private TypeService typeService;

    /**
     * 跳转到主页面
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/type.html";
    }

    /**
     * 新增页面
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/type_add.html";
    }

    /**
     * 编辑页面
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/type_edit.html";
    }

    /**
     * 新增接口
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TypeParam typeParam) {
        this.typeService.add(typeParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TypeParam typeParam) {
        this.typeService.update(typeParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TypeParam typeParam) {
        this.typeService.delete(typeParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TypeParam typeParam) {
        Type detail = this.typeService.getById(typeParam.getTypeId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author SYT
     * @Date 2020-10-13
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TypeParam typeParam) {
        return this.typeService.findPageBySpec(typeParam);
    }

    @ResponseBody
    @RequestMapping("/getAll")
    public List<TypeResult> getALLByclassification(int classification) {
        return this.typeService.getALLByclassification(classification);
    }

}


